﻿//========================================
// All rights reserved (C) 2017-2100
// CLR 版本：	4.0.30319.42000
// 命名空间:	SFJDService.SocketHandle
// 文 件 名：	DictionaryInitialize
// 作    者：	WooG
// 联系方式：	wooglle@163.com
// 创建时间：	2017/9/27 14:46:31
//========================================
using System;
using System.Collections.Generic;

namespace SFJDService.SocketHandle
{
    public class DictionaryInitialize
    {
        private int code = 0;
        private static Dictionary<int, Type> dictionary = new Dictionary<int, Type>(50);

        public DictionaryInitialize()
        {
            if(dictionary.Count > 0)
            {
                return;
            }
            else
            {
                Initialize();
            }
        }

        private void Initialize()
        {
            AddClient2ServerHandle();
            code = dictionary.Count;
            AddServer2SeverHandle();
        }

        private void AddClient2ServerHandle()
        {
            dictionary.Add(1, typeof(PH01RegisterCase));
            dictionary.Add(2, typeof(PH02Brigade));
            dictionary.Add(3, typeof(PH03Contact));
            dictionary.Add(4, typeof(PH04User));
            dictionary.Add(5, typeof(PH01Request2EditData));
            dictionary.Add(6, typeof(PH01Request2RemoveLast));
            dictionary.Add(7, typeof(PH02Request2EditBrigade));
            dictionary.Add(8, typeof(PH02Request2RemoveBrigade));
            dictionary.Add(9, typeof(PH03Request2RemoveContact));
            dictionary.Add(10, typeof(PH04Request2EditUser));
            dictionary.Add(11, typeof(PH05Transport));
            dictionary.Add(12, typeof(PH06Update));
            dictionary.Add(13, typeof(PH01RequestSynData));
        }

        private void AddServer2SeverHandle()
        {
            code = 100;
            AddDictionary(typeof(PH01GetData));
            AddDictionary(typeof(PH01GotData));
            AddDictionary(typeof(PH01AddData));
            ////
            AddDictionary(typeof(PH01EditData));
            AddDictionary(typeof(PH01EditData));
            AddDictionary(typeof(PH01EditData));
            AddDictionary(typeof(PH01RemoveLast));
            AddDictionary(typeof(PH01GotDataLast));
            AddDictionary(typeof(PH01PullDataLast));
            AddDictionary(typeof(PH01SynDataCheckSe));
            AddDictionary(typeof(PH01SynDataCheckRe));
            AddDictionary(typeof(PH01SynDataCheckErr));
            AddDictionary(typeof(PH01SynGetNetMax));
            AddDictionary(typeof(PH01SynGotNetMax));

            AddDictionary(typeof(PH02GetFileSize));
            AddDictionary(typeof(PH02GotFileSize));
            AddDictionary(typeof(PH02PublishWinner));
            AddDictionary(typeof(PH02AddBrigade));
            AddDictionary(typeof(PH02EditBrigade));
            AddDictionary(typeof(PH02RemoveBrigade));

            AddDictionary(typeof(PH03GetFileSize));
            AddDictionary(typeof(PH03GotFileSize));
            AddDictionary(typeof(PH03PublishWinner));
            AddDictionary(typeof(PH03AddContact));
            AddDictionary(typeof(PH03RmoveContact));

            AddDictionary(typeof(PH04AddUserAdmin));
            AddDictionary(typeof(PH04AddUserOridary));
            AddDictionary(typeof(PH04EditUser));

            AddDictionary(typeof(PH05ReGotRequest));
            AddDictionary(typeof(PH05SeRequestReply));
            AddDictionary(typeof(PH05ReGotTransInfo));
            AddDictionary(typeof(PH05SeStratSend));
            AddDictionary(typeof(PH05ReStartReceive));

            AddDictionary(typeof(PH06GetVersion));
            AddDictionary(typeof(PH06GotVersion));
            AddDictionary(typeof(PH06GetUpdateFiles));
            AddDictionary(typeof(PH06GotUpdateFiles));
            AddDictionary(typeof(PH06PushFiles));

            AddDictionary(typeof(PH07OnLine));
            AddDictionary(typeof(PH07OffLine));
            AddDictionary(typeof(PH07ActivingUser));
        }

        private void AddDictionary(Type type)
        {
            code++;
            dictionary.Add(code, type);
        }

        public Dictionary<int, Type> GetDictionary()
        {
            if(dictionary.Count == 0)
            {
                Initialize();
            }
            return dictionary;
        }
    }
}
